package com.hy.study.mapper;

import com.hy.study.bean.OrderBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * NullWritable 表示不需要任何值 不需要输出
 *
 * @author huyong
 * @date 2024 年 02 月 05 日 17:41: 51
 */
public class OrderMapper extends Mapper<LongWritable, Text, OrderBean, NullWritable> {
    private final OrderBean beanKey = new OrderBean();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, OrderBean, NullWritable>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split("\t");
        int orderId = Integer.parseInt(split[0]);
        double price = Double.parseDouble(split[2]);
        beanKey.setOrderId(orderId);
        beanKey.setPrice(price);
        context.write(beanKey, NullWritable.get());
    }
}
